<?php

@$bank_id = $_REQUEST['function'];
@$v2 = $_REQUEST['v2'];

$currency = 'quadrans';

$user = new user($user_id);
$user_info[$user_id] = $user->load_tables('user_finances');

$bank = new bank_class($bank_id);

$bank_name = $bank->info['name'];

echo "<h1>$bank_name</h1>";

    
echo '<p>';
echo "Welcome to <B>$bank_name</B>.";
echo '</p>';


if ($bank->has_account($user_id))
{
	echo $bank->atm();
}
else 
{
	echo $bank->get_link('new_account');
	echo $bank->get_link('rates');
}


if (@$_REQUEST['v1'] == 'atm')
{
	
	if (!$bank->is_valid_account($_REQUEST['which_account']))
		{	
			echo 'please do not try and cheat. we are now watching you.';
			exit;
		}
	
	if ($_REQUEST['amount'] > 0 && $_REQUEST['amount'] < 1000000)
	{
		$amount = $_REQUEST['amount'];
	}
	else 
	{
		$amount = 0;
	}
	
	if ($_REQUEST['do_what'] == 'deposit')
	{
		# check if user has enough money in pocket to deposit 
		if ($user_info[$user_id][$currency] >= $amount)
		{
			$bank->user_debit($user_id, $amount, $currency);
			$bank->bank_credit($bank_id, $amount, $currency);
			echo '<pre>Done</pre>';
		}
		else 
		{
			echo '<pre>Sorry, not possible. You do not have enough money in hand!</pre>';
		}
	}	
	
	elseif ($_REQUEST['do_what'] == 'withdraw')
	{
		# check if user has enough money in pocket to deposit 
		if ($bank->money_available() >= $amount)
		{
			$bank->user_credit($user_id, $amount, $currency);
			$bank->bank_debit($bank_id, $amount, $currency);
			echo '<pre>Done</pre>';
		}
		else 
		{
			echo '<pre>Sorry, not possible. The bank does not have enough money available at the present time!</pre>';
		}
	}
}


?>